<template>
	<view class=" tjxq">
		<view class="tjxqone">
			<view class="headerimg">
				<u-image width="100%" :src="data.TJMainImg" mode="widthFix"></u-image>
			</view>
			<view class="tjtextnr">
				<view class="nrone">
					<view class="nrtitel">
						{{data.TJName}}
					</view>
					<view class="nrdz">
						<!-- <u-icon name="account-fill" size="30"></u-icon>
						&nbsp;{{user.Name}} -->
					</view>
					<view class="nrprice color1">
						<span>￥&nbsp;</span>
						<span>{{data.TJPrice}}</span>
					</view>
				</view>
				<view class="nrsj" style="color: gray;">
					<view class="yysj" style="display: flex; color: black;" >
						<view class="">
							<u-icon name="clock" size="30"></u-icon>
						</view>
						<view class="" style="display: flex;">
							&nbsp;<span>预约时间&nbsp;</span>
							<span style="color: red;">*</span>
							<span>:&nbsp;</span>
						</view>
						<view :class="time!=''?'gray':'red'">
							<myTime @getTime="getMyTime" :TJTestId="TJTestId"></myTime>
						</view>
					</view>
				</view>
				<view class="nrwxts">
					<view class="" style="width: 50%;font-size: 30rpx;">
						<u-tabs :list="list" :is-scroll="false" v-model="current" @change="change"></u-tabs>
					</view>
					<view class="wxbox a" v-if="current==0">
						<view class="" style="color: gray;">
							&emsp;&emsp;{{data.TJDetail}}
						</view>
					</view>
					<view class="wxbox b" v-else>
						<span>在您进行体检预约时，请仔细阅读以下须知：</span>
						<span class="te">一、预约时间</span>
						<span class="tex">1.请提前进行预约，以确保我们能为您提供更好的服务。</span>
						<span class="te">二、预约信息</span>
						<span class="tex">1.请确保您填写的个人信息准确无误，包括姓名、性别、年龄、联系方式等，避免无法正常体检。</span>
						<span class="tex">2.请根据自身情况选择合适的体检套餐，如有特殊需求，请在预约信息中详细注明</span>
						<span class="te">三、取消与更改</span>
						<span class="tex">1.如需取消或更改预约，请提前联系我们，以便我们进行相应调整。</span>
						<span class="tex">2.如未在规定时间内取消或更改预约，可能会产生一定的费用或影响您的后续预约服务。</span>
						<span class="te">四、体检准备</span>
						<span class="tex">1.体检前 [X] 天，请保持清淡饮食，避免饮酒和剧烈运动。</span>
						<span class="tex">2.体检当天，请空腹前往体检中心，部分项目可能需要憋尿，请提前做好准备。</span>
						<span class="te">五、其他事项</span>
						<span class="tex">1.请携带有效身份证件参加体检。</span>
						<span class="tex">2.请遵守体检中心的各项规章制度，听从工作人员的安排。</span>
					</view>
				</view>
				<!-- 在a和b在显示和隐藏的时候添加渐隐渐变加左右翻转的动画 -->
			</view>
		</view>
		<view class="tjxqtwo">
			<view class="tjbotton bacnone2" @click="SubmitOrder">
				<span>提交预约</span>
			</view>
		</view>
	</view>
</template>

<script>
	import myTime from './compoent/myTime.vue'
	export default {
		components: {
			myTime
		},
		data() {
			return {
				list: [{
					name: '温馨提示'
				}, {
					name: '预约须知'
				}],
				current: 1,
				cuindex: 1,
				src: '/static/ttjj.png',
				user: {
					PatientId: '',
					Name: ''
				},
				Number:'',
				time: '',
				data: {
					TJTestId: "",
					TJName: "",
					TJHisCode: "",
					TJDescription: "",
					TJCategoryId: "",
					TJCategory: "",
					TJMainImg: "",
					TJPrice: '',
					TJDetail: "",
					TJBuyCount: null,
					TJMaxCout: '',
					TJStatus: 1,
					TJCreateDatetime: "",
					TJSortCode: 1
				},
				TJChildId: '',
				TJTestId: ''
			}
		},
		onLoad: function(option) {
			// console.log("选择套餐", option)
			this.TJChildId = option.TJChildId
			this.TJTestId = option.TJTestId
			console.log("选择套餐", option)
			this.GetTJTestDetail()
		},
		computed: {

		},
		methods: {
			confirm(e) {
				// let money = parseInt(e)
				let then=this
				
				this.$request("Order", "Submit", {
					PatientId: this.items.PatientId,
					TimeSpaceId: this.doctor.timeId,
					Memo: this.Disease
				}).then(res => {
					console.log("提交订单res", res)
					// uni.hideLoading();
					// uni.showToast({
					// 	title: "成功预约",
					// 	icon: "none",
					// 	duration: 2000,
					// });
					if(res.code!=1){
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2000,
						});
						return
					}
					if (res.data.PayStatus == 1) {
						this.$request("pay","pay",{
								OrderNo:res.data.OrderNo,
							}).then(resa=>{
								console.log("订单号",res)
								WeixinJSBridge.invoke('getBrandWCPayRequest', {
										"appId": resa.data.appId, //公众号ID，由商户传入     
										"timeStamp": resa.data.timeStamp, //时间戳，自1970年以来的秒数     
										"nonceStr": resa.data.nonceStr, //随机串     
										"package": resa.data.package,
										"signType": resa.data.signType, //微信签名方式：     
										"paySign": resa.data.paySign //微信签名 
									},
									function(res) {
										// then.sss=res
										// console.log("支付",res)
										if (res.err_msg == "get_brand_wcpay_request:ok") {
											uni.showToast({
												title: "成功支付",
												icon: "none",
												duration: 2000,
											});
											setTimeout(function() {
												uni.reLaunch({
													// url: `/pages/register/Scheduling/record/record?current=${3}`,
													url: '/pages/zhuyaun/xxoo/xxoo',
													fail(error) {
														console.log(error)
													}
												})
											}, 2000);
										}else{
											uni.showToast({
												title: "支付未成功",
												icon: "none",
												duration: 2000,
											});
											setTimeout(function() {
												uni.reLaunch({
													// url: `/pages/register/Scheduling/record/record?current=${2}`,
													url: '/pages/zhuyaun/xxoo/xxoo',
													fail(error) {
														console.log(error)
													}
												})
											}, 2000);
										}
									});
							})
						
					} else {
						uni.reLaunch({
							// url: `/pages/register/Scheduling/record/record`,
							url: '/pages/zhuyaun/xxoo/xxoo',
							fail(error) {
								console.log(error)
							}
						})
						return
					}
				})
			
			
			},
			SubmitOrder() {
				if(this.time==''){
					uni.showToast({
						title: '请先选择体检日期',
						icon: 'none',
						duration: 2000
					});
					return
				}else if(this.Number==0)
				{
					
					uni.showToast({
						title: '当前可预约人数为0',
						icon: 'none',
						duration: 2000
					});
					return
					
					
				}
				uni.showLoading({
					title: '正在提交体检预约',
					mask: true
				});
				console.log(this.TJTestId,this.TJChildId,this.time)
				this.$request("RegTJRecord", "SubmitOrder", {
					TJTestId: this.TJTestId,
					TJChildId:this.TJChildId,
					TJRegDatetime:this.time
				}).then(res => {
					console.log("提交", res)
					if (res.code == 1) {
						// this.data = res.data
						
						uni.hideLoading();
						uni.showToast({
							title: '体检预约提交成功',
							icon: 'none',
							duration: 2000
						});
						uni.redirectTo({
							url:'/pages/zhuyaun/tijian/tijianlist'
						})
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			GetTJTestDetail() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				this.$request("TJCategory", "GetTJTestDetail", {
					TJTestId: this.TJTestId
				}).then(res => {
					console.log("套餐详情", res)
					if (res.code == 1) {
						this.data = res.data
						uni.hideLoading();
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			change(index) {
				console.log("index", index);
			},
			getMyTime(e,e1) {
				console.log("e", e1)
				this.time = e
				this.Number=e1
			},
		}
	}
</script>

<style>
	@import './project.css';
</style>